/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ContentManagers.Security;

import DBConnection.ConnectionFactory;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 *
 * @author Ervin James
 */
public abstract class WebLogger {
    
    public static void insertLog(String ip, String referer, String uri, String description, boolean success)
    {
         try{
            //opens db connection
            ConnectionFactory myFactory = ConnectionFactory.getFactory("logger");
            Connection conn = myFactory.getConnection();

            int i = 1;
            
            PreparedStatement pstmt;
            
            //SQL Query
            if(success)
                pstmt = conn.prepareStatement("INSERT INTO success_logs (ip_address , referer, uri, description) VALUES(?,?,?,?)");
            else
                pstmt = conn.prepareStatement("INSERT INTO error_logs (ip_address , referer, uri, description) VALUES(?,?,?,?)");
            //include parameters
            
            pstmt.setString(i++, ip);
            pstmt.setString(i++, referer);
            pstmt.setString(i++, uri);
            pstmt.setString(i++, description);

            //execute query
            pstmt.executeUpdate();


            //close DB connection
            conn.close();

            }
            catch(SQLException e)
            {
               e.printStackTrace();
            } 
    }

    
}
